package com.xlh.controller.conclude;

/**
 * @author cfz
 */

import com.github.pagehelper.PageInfo;
import com.xlh.common.Result;
import com.xlh.dto.conclude.ConcludeParamDTO;
import com.xlh.param.conclude.ClassImportParam;
import com.xlh.service.conclude.ConcludeStudentService;
import com.xlh.vo.conclude.ConCludeClassStudentVO;
import com.xlh.vo.conclude.StudentListInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * 工程认证 - 课程达成度
 * <p>
 * chufangzheng
 */
@Api(tags = "ConcludeStudentController", description = "工程认证 - 学生类")
@RestController
@RequestMapping("/conclude/student")
public class ConcludeStudentController {

    @Autowired
    private ConcludeStudentService concludeStudentService;


    @ApiOperation("学生列表")
    @GetMapping("/list")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<PageInfo<StudentListInfoVO>> list(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum ,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize ,
            @RequestParam(value = "concludeId") Long concludeId,
            @RequestParam(value = "className") String className){
        PageInfo<StudentListInfoVO> page = concludeStudentService.list(pageNum, pageSize, concludeId, className);
        return Result.success(page);
    }

    @ApiOperation("班级列表")
    @GetMapping("/class/list")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<List<String>> classList(@RequestParam(value = "concludeId") Long concludeId,
                                          @RequestParam(value = "className") String className){
        List<String> list = concludeStudentService.classList(concludeId, className);
        return Result.success(list);
    }

    @ApiOperation("学生修改")
    @PutMapping("/update")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result update(@RequestBody @Valid StudentListInfoVO dto){

        concludeStudentService.update(dto);
        return Result.success();
    }

    @ApiOperation("学生批量删除")
    @DeleteMapping("/delete/batch")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result delete(@RequestBody List<ConcludeParamDTO> concludeIds){
        concludeStudentService.delete(concludeIds);
        return Result.success();
    }

    @ApiOperation("导入学生")
    @PostMapping("/excel/import")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<String> importExcel(@RequestParam(value = "concludeId") Long concludeId
            ,@RequestParam(value = "file") MultipartFile file){

        concludeStudentService.importExcel(concludeId, file);
        return Result.success();
    }

    @ApiOperation("学生班级导入")
    @PostMapping("/class/import")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result classImport(@RequestBody ClassImportParam classImportParam){

        concludeStudentService.classImport(classImportParam.getStudentIds(),
                    classImportParam.getConcludeId(), classImportParam.getClassId());
        return Result.success();
    }

    @ApiOperation("展示已经导入的学生")
    @GetMapping("/class/students")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result classStudents(Long classId, Long concludeId){

        List<ConCludeClassStudentVO>  conCludeClassStudentVOS = concludeStudentService.classStudents(classId, concludeId);

        return Result.success(conCludeClassStudentVOS);
    }






}
